package com.r7data.dbstruct.demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JdbcTest {

	
	
	
	public static void getMysqlCon(){
		
		String dbUrl = "jdbc:mysql://localhost:3306/other_test";

		//String driverClass = "com.mysql.jdbc.DriverR7";
		String driverClass = "oracle.jdbc.driver.OracleDriver";
		
		//String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		
		String dbUser = "root";
		String dbPassword = "admin";
		
		try {
			//Class.forName(driverClass);
			
			Connection con = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
			
			String sql = "select className from `classinfo` ";
			
			PreparedStatement pst = null;
			ResultSet rst = null;
			
			pst = con.prepareStatement(sql);
			rst = pst.executeQuery();
			
			while(rst.next()){
				
				String tableName = rst.getString(1);
				
				System.out.println(tableName);
				
			}
			
			
			rst.close();
			pst.close();
			con.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public static void getOraclCon(){
		
		String dbUrl = "jdbc:oracle:thin:@172.16.6.215:1521/orcl";
		
		//String driverClass = "oracle.jdbc.driver.OracleDriver";
		String driverClass = "com.mysql.jdbc.Driver";
		
		String dbUser = "cty";
		String dbPassword = "cty";
		
		
		//getMysqlCon();
		
		try {
			
			//Class.forName(driverClass);
			
			Connection con = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
			
			String sql = "select table_name from tabs ";
			
			PreparedStatement pst = null;
			ResultSet rst = null;
			
			pst = con.prepareStatement(sql);
			rst = pst.executeQuery();
			
			while(rst.next()){
				
				String tableName = rst.getString(1);
				
				System.out.println(tableName);
				
			}
			
			
			rst.close();
			pst.close();
			con.close();
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {
		
		getMysqlCon();
		
		System.out.println("finished ... ");
		
	}
	
}
